﻿#if SRP_URP
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Rendering;

namespace GameToolkit
{
    public class VolumeProfileClip : PlayableAsset
    {
        [SerializeField]
        public VolumeProfile m_Profile;
        public VolumeProfile profile { get { return m_Profile; } }

        public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
        {
            var playable = ScriptPlayable<VolumeProfilePlayable>.Create(graph);
            playable.GetBehaviour().profile = m_Profile;
            return playable;
        }

        class VolumeProfilePlayable : PlayableBehaviour
        {
            public VolumeProfile profile;
            VolumeProfileMixer mMixer;

            public override void OnGraphStart(Playable playable)
            {
                var output = playable.GetOutput(0);
                mMixer = ((ScriptPlayable<VolumeProfileMixer>)output).GetBehaviour();
            }

            public override void ProcessFrame(Playable playable, FrameData info, object playerData)
            {
                //var output = playable.GetOutput(0);
                //var behaviour = ((ScriptPlayable<VolumeProfileMixer>)output).GetBehaviour();
                mMixer.OverrideSettings(new VolumeProfileBlend(profile, info.weight));
            }

        }
    }
}
#endif